/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.bean;

import ejb.entity.Account;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Nothing4ever
 */
@Stateless
public class AccountFacade extends AbstractFacade<Account> {

    @PersistenceContext(unitName = "KscEventEjbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AccountFacade() {
        super(Account.class);
    }

    public Account login(Account account) {
        String sql = "SELECT a FROM Account a WHERE a.username = :username AND a.password= :password";
        TypedQuery<Account> query = em.createQuery(sql, Account.class);
        query.setParameter("username", account.getUsername());
        query.setParameter("password", account.getPassword());
        return query.getSingleResult();

    }
}
